Skip to content

Add JSON response mode to Streamable HTTP server#1714

Open
lntutor wants to merge 1 commit into
modelcontextprotocol:mainfrom
lntutor:feat/json-only-545
Open

Add JSON response mode to Streamable HTTP server#1714
lntutor wants to merge 1 commit into
modelcontextprotocol:mainfrom
lntutor:feat/json-only-545

Conversation

@lntutor

@lntutor lntutor commented Jul 19, 2026

Copy link
Copy Markdown

Summary

  • add opt-in EnableJsonResponse configuration for ASP.NET Core and StreamableHttpServerTransport
  • return the final correlated JSON-RPC response directly as application/json without SSE framing
  • omit intermediate request-related messages and POST event-store writes in JSON mode
  • preserve default SSE behavior, empty 202 Accepted notification responses, and standalone GET SSE streams
  • reject polling when JSON responses are enabled and document the transport tradeoffs

Testing

  • dotnet test tests/ModelContextProtocol.AspNetCore.Tests/ModelContextProtocol.AspNetCore.Tests.csproj --filter FullyQualifiedName~JsonResponseModeTests --no-restore (15 passed across net8.0, net9.0, and net10.0)
  • dotnet test tests/ModelContextProtocol.AspNetCore.Tests/ModelContextProtocol.AspNetCore.Tests.csproj -f net10.0 --no-restore --filter "(Execution!=Manual)" (512 passed)
  • dotnet test ModelContextProtocol.slnx --configuration Release --no-build --filter "(Execution!=Manual)" (8,454 passed)
  • dotnet build ModelContextProtocol.slnx --configuration Release (36 projects, 0 warnings)
  • dotnet format ModelContextProtocol.slnx --no-restore --verify-no-changes --include ...
  • dotnet docfx docs/docfx.json --warningsAsErrors true (0 warnings)

Fixes #545

/// Request-related notifications and other intermediate messages are not included in the response. Standalone GET
/// requests continue to use SSE when stateful mode is enabled.
/// </remarks>
public bool EnableJsonResponse { get; set; }

@halter73 halter73 Jul 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EnableJsonResponse name and ordinary POST behavior match other SDKs, but those SDKs still permit SSE for cases such as subscriptions/listen or standalone GET. Is that the contract we want, or should this be an explicit mode API like ResponseMode = HttpResponseMode.JsonOnly?

For deployments where intermediaries buffer streaming responses, JsonOnly should mean no SSE anywhere. Ordinary POSTs return JSON, GET returns 405, subscriptions/listen returns a correlated MethodNotFound, and EnableLegacySse is incompatible.

We could add a JsonPreferred mode if the hybrid behavior is valuable, but I suspect disabling SSE entirely is the primary use case. Am I off base here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support a non-SSE JSON-only mode similar to the TypeScript SDKs enableJsonResponse: true

2 participants